package com.yupi.springbootinit.utils.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author shxl2021
 * @Date 2023/8/11 15:53
 * @Version 1.0
 */
public class FileRead {
    public static List<String> readFile(String path) throws Exception {
        return readFile(path, null);
    }

    public static List<String> readFile(String path, Comparable<String> comparable) throws Exception {
        File file = new File(path);
        FileReader fileReader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String s;
        ArrayList<String> list = new ArrayList<>();
        while ((s = bufferedReader.readLine()) != null) {

            if (comparable != null && comparable.compareTo(s) > 0) {
                list.add(s);
            }
            if (comparable == null) {
                list.add(s);
            }
        }
        return list;
    }
}
